package xyz.robinbingo.leetcode.a20.b05.c15;

public class Solution {
    public int subarraySum(int[] nums, int k) {
        int[] sums = new int[nums.length + 1];
        sums[0] = 0;
        int sum = 0;
        int result = 0;

        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            sums[i + 1] = sum;
        }

        for (int i = 0; i < nums.length; i++) {
            for (int j = i; j < nums.length; j++) {
                if (k == sums[j + 1] - sums[i]) {
                    result++;
                }
            }
        }
        return result;
    }
}